package com.LeeCode;

/**
 * 包含所有 1 的最小矩形面积 I
 */

public class Code3195 {
    public static void main(String[] args) {

    }

    public int minimumArea(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int minRow = -1, maxRow = -1, minCol = -1, maxCol = -1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 1) {
                    if (minRow == -1 || i < minRow) minRow = i;
                    if (maxRow == -1 || i > maxRow) maxRow = i;
                    if (minCol == -1 || j < minCol) minCol = j;
                    if (maxCol == -1 || j > maxCol) maxCol = j;
                }
            }
        }
        int area = (maxRow - minRow + 1) * (maxCol - minCol + 1);
        return area;
    }

}
